
<template>
  <div>
    <el-alert
      v-show="questions.length==0"
      type="warning"
      description="无考核内容"
      center
    >
    </el-alert>
    <div
      v-for="(quData,index) in questions"
      :key="quData.id"
      v-show="questions.length>0"
    >
      <p>{{index+1}}.{{quData.stem}}</p>
      <div v-if="quData.type == 1 ">
        <el-radio-group v-model="radioValue">
          <el-radio
            v-for="item in quData.option"
            :label="item.id"
            :key="item.id"
          >{{ item.name}}.{{item.content}}
            <div
              v-if="item.image!=null && item.image!=''"
              style="clear: both"
            >
              <el-image
                :src="item.image"
                style="max-width:100%;"
              />
            </div>
          </el-radio>
        </el-radio-group>
      </div>
      <!-- 多选题 -->
      <div v-if="quData.type == 2">
        <el-checkbox-group v-model="multiValue">
          <el-checkbox
            v-for="item in quData.option"
            :label="item.id"
            :key="item.id"
          >{{ item.name }}.{{ item.content }}
            <div
              v-if="item.image!=null && item.image!=''"
              style="clear: both"
            >
              <el-image
                :src="item.image"
                style="max-width:100%;"
              />
            </div>
          </el-checkbox>
        </el-checkbox-group>

      </div>
      <!-- 判断题 -->
      <div v-if="quData.type == 3">
        <el-radio-group v-model="radioValue">
          <el-radio label="1">对 </el-radio>
          <el-radio label="0">错 </el-radio>
        </el-radio-group>

      </div>
      <!-- 问答题 -->
      <div v-if="quData.type == 4">
        <el-input
          type="textarea"
          v-model="questionValue"
          placeholder="请填写答案"
        ></el-input>
      </div>
    </div>
  </div>

</template>
<script>
import { mapGetters, mapState } from "vuex";
import { getTrainTest } from "@/api/vadmin/train/train";
import variables from "@/assets/styles/variables.scss";
export default {
  name: "newKnowledge",
  data() {
    return {
      // 遮罩层
      loading: true,
      data: "",
      show: false,
      questions: [],
      radioValue: "",
      multiValue: [],
      questionValue: "",
      chapter: "",
    };
  },
  props: ["chapterId"],
  watch: {
    chapterId(val) {
      this.chapter = val;
    },
  },
  computed: {
    ...mapState(["settings"]),
    variables() {
      return variables;
    },
    theme() {
      return this.$store.state.settings.theme;
    },
  },

  mounted() {
    this.getChapterTest();
  },
  created() {
    this.getChapterTest();
  },
  methods: {
    // 获取题目
    getChapterTest() {
      if (this.chapter !== "") {
        getTrainTest({ chapter: this.chapter }).then((res) => {
          // console.log("本章测验", res);
        });
      }
    },
  },
};
</script>
